<?php
namespace app\bsadmin\controller;
use think\facade\View;
use think\facade\Cache;
use think\facade\Validate;
use app\common\model\SmsSendLog as SmsSendLogModel;
use helper\Dir;
use XYCms\Sms as SmsXYCms;

class Sms extends Base
{
    public function index()
    {
    	if (request()->isAjax()) {
    		$G=request()->get();
            $where=[];
            if (!empty($G['username'])) {
                $where[]=['username','=',$G['username']];
            }
            if (!empty($G['ip'])) {
                $where[]=['ip','=',$G['ip']];
            }
            $whereTime=[];
            if (!empty($G['time'])) {
                $whereTime[]=strtotime($G['time'][0].' 00:00:00');
                $whereTime[]=strtotime($G['time'][1].' 23:59:59');
            }
            $ListObj=SmsSendLogModel::where($where);
            if(!empty($whereTime)){
                $ListObj->whereTime('create_time','between',$whereTime);
            }
            $Data=$ListObj->order('id desc')->paginate($G['pageSize'])->each(function($v){
                    return $v;
                });
            if ($Data->items()) {
                return $this->ajaxReturn('',0,$Data);
            }else{
                return $this->ajaxReturn('暂无数据~',-100);
            }
    	}else{
            try {
                $SmsXYCms=new SmsXYCms;
                $ret=$SmsXYCms->getSmsUser();
                View::assign('countData',$ret);
            } catch (\think\Exception $e) {
            }
	    	return View::fetch();
    	}
    }
}
